package com.ljm.security.controller;

import com.ljm.common.dto.BaseResult;
import com.ljm.common.dto.UserInfoDto;
import com.ljm.common.util.ResultUtil;
import com.ljm.security.dto.SecurityUserInfoDto;
import com.ljm.security.util.UserUtil;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenHuaming
 */
@RestController
public class SecurityController {
    private final static MapperFacade MAPPER_FACADE;
    static {
        MapperFactory mapperFactory=new DefaultMapperFactory.Builder().build();
        mapperFactory.classMap(UserInfoDto.class,SecurityUserInfoDto.class).byDefault().register();
        MAPPER_FACADE=mapperFactory.getMapperFacade();
    }
    @RequestMapping(method = RequestMethod.GET,value = "/getUserInfo")
    public BaseResult getUserInfo(){
        SecurityUserInfoDto userInfo=new SecurityUserInfoDto();
        UserInfoDto curUser = UserUtil.getCurUser();
        MAPPER_FACADE.map(curUser,userInfo);
        userInfo.setRoles(UserUtil.getRole());
        userInfo.setPermissions(UserUtil.getPermission());
        return ResultUtil.successData(userInfo);
    }
}
